import React, { Component } from 'react';
import Http from '../../util/http';
import Wheaders from '../../components/Headers';
import { Input, Button, message } from 'antd';
import './index.less'

const { TextArea } = Input;

class CreatComment extends Component {
    constructor(props){
        super(props);
        this.state = {
            novelId: props.location.state.novelId,
            value: '',
        }
    }

    render() {
        return (
            <div className='education-createComment'>
                <Wheaders left={'返回'} middle={'写评论'} right={'我的'} />
                <div className={'main'}>
                    <TextArea className={'text'} onChange={ (e) => { this.setState({value: e.target.value}); }} placeholder={'请输入你的评论'} bordered={false} showCount  maxLength={500}/>
                    <Button type={'default'} onClick={this.creatComment.bind(this)} block>发表</Button>
                </div>
            </div>
        );
    }

    UNSAFE_componentWillMount() {

    }

    componentDidMount() {

    }

    creatComment () {
        Http.post('/Comment/createComment', {
            novelId: this.state.novelId,
            content: this.state.value
        }).then( (res) => {
            message.success('评论成功', 0.5, () => {
                this.props.history.goBack();
            })
        } )
    }

}
export default CreatComment;


